package org.inspursc.s0517.health.evaluation.converter;


import com.alibaba.fastjson.JSON;
import org.inspursc.s0517.health.evaluation.dto.InsAnRadioDTO;
import org.inspursc.s0517.health.evaluation.entity.InsAnRadio;
import org.springframework.beans.BeanUtils;

import java.util.Arrays;


/**
 *institution assessment convert
 */
public class InsAnRadioConverter {

    public static InsAnRadio converter(InsAnRadioDTO anDTO) {
        InsAnRadio an = new InsAnRadio();
        BeanUtils.copyProperties(anDTO, an);
        an.setOtherOptionsAnswer(JSON.toJSONString(anDTO.getOtherOptionsAnswer()));
        StringBuilder sb=new StringBuilder();
        for(String str:anDTO.getOtherOptionsAnswer()){
            sb.append(str);
            sb.append("||");
        }
        return an;
    }

    public static InsAnRadioDTO converter(InsAnRadio an) {
        InsAnRadioDTO anDTO = new InsAnRadioDTO();
        BeanUtils.copyProperties(an, anDTO);
        //todo
//        List<String> list=JSONObject.parseArray(an.getOtherOptionsAnswer(),String.class);
        String[] str=  an.getOtherOptionsAnswer().split("\\|");
        anDTO.setOtherOptionsAnswer(Arrays.asList(str));
        return anDTO;
    }

}
